/** 
 * This file is a part of qloudgen-sec. 
 * You can redistribute qloudgen-sec and/or modify it under the terms of the Lesser GNU General Public License version 3. 
 * qloudgen-sec is distributed WITHOUT ANY WARRANTY. 
 *
 * See the Lesser GNU General Public License for more details at http://www.gnu.org/licenses/. 
 **/
package org.qloudgen.sec.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>Title: HTTP filter tools.</p>
 * <p>Description: Implementation http request and response print.</p>
 * <p>Copyright: qloudgen/sec 2010</p>
 * @author <a href="mailto:hyq.dd.sun@gmail.com">glue.3M</a>
 */
public final class HttpFilterUtil implements Filter {

	/**
	 *
	 */
	public void init(final FilterConfig filterConfig) {
		// Nothing needs todo.
	}
	
	/**
	 *
	 */
	public void destroy() {
		// Nothing needs todo.
	}

	/**
	 *
	 *
	 * @param servletRequest
	 * @param servletResponse
	 * @param filterChain
	 */
	public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException , ServletException {
		//
		try {
			HttpUtil.print( ( HttpServletRequest )servletRequest , ( HttpServletResponse )servletResponse );
		}
		catch (Throwable t) {
			throw new ServletException( t );
		}
		finally {
			// Other filters
			filterChain.doFilter( servletRequest , servletResponse );
		}
	}
}